package Array;

import java.util.Stack;

public class lc844 {
    public boolean backspaceCompare(String s, String t) {
        Stack<Character> stacks = new Stack<>();
        Stack<Character> stackt = new Stack<>();
        char[] sc = s.toCharArray();
        char[] tc = t.toCharArray();
        for (char c: sc) {
            if (c != '#') {
                stacks.push(c);
            } else if (!stacks.isEmpty()){
                stacks.pop();
            }
        }
        for (char c: tc) {
            if (c != '#') {
                stackt.push(c);
            } else if (!stackt.isEmpty()){
                stackt.pop();
            }
        }
        return stacks.equals(stackt);
    }
}